package com.hundsun.s3.platform.monitor.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import com.hundsun.s3.common.dto.SR;
import com.hundsun.s3.common.util.BaseDao;


/**
 * 
 * <p>Title:SrAddAndSave</p>
 * <p>Description: </p>
 * <p>Company: Hundsun</p>
 * @author :zhangwc23609
 * @date :2018年3月5日 下午4:53:56
 */
@Service
public class SrAddAndSave extends BaseDao{
	
	/**
	 * 
	 * @Description:通过传入的SR，进行格式转换，并计算时间差，然后调用功能号进行新增数据
	 * @param sr
	 * @author: zhangwc23609
	 * @date: 2018年3月5日 下午4:54:10
	 */
	public void AddSr(SR sr){
		Map<String, Object> map = new HashMap<String,Object>();
		
		Logger logger = Logger.getLogger(SrAddAndSave.class.getName());
		//取数据
		String srId = sr.getSrId();
		String staffId = sr.getStaffId();
		Integer clientId = Integer.parseInt(sr.getClientId());
		String generateTime = sr.getGenerateTime().toString();
		String serviceTime = sr.getServiceTime().toString();
		String endTime = sr.getEndTime().toString();
		String timeStep = sr.getTimeStep();
		String chatStep = sr.getChatStep();
		Long l = null;
		Long c = null;
		//格式转换
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		try {
			Date gTtemp = sdf.parse(generateTime);
			Date sTtemp = sdf.parse(serviceTime);
			Date eTtemp = sdf.parse(endTime);
			//计算时间差
			l = (sTtemp.getTime() - gTtemp.getTime()) / 1000;
			c = (eTtemp.getTime() - sTtemp.getTime()) / 1000;
			logger.info("计算时间差成功！");
		} catch (Exception e) {
			logger.error("计算时间差失败！");
		}
		timeStep = l.toString();
		chatStep = c.toString();
		//准备存数据
		map.put("srId", srId);
		map.put("staffId", staffId);
		map.put("clientId", clientId);
		map.put("timeStep", timeStep);
		map.put("chatStep", chatStep);
		String result = this.exc("600103", map);
		if("执行成功".equals(result)){
			logger.info("插入SR成功");
		}else{
			logger.error("插入SR失败");
		}
	}
	
	
	
	
}
